package logic

import (
	"context"
	"errors"
	"goods/models/redisinit"

	"goods/goods"
	"goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelCartLogic {
	return &DelCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelCartLogic) DelCart(in *goods.DelCartRequest) (*goods.DelCartResponse, error) {
	// todo: add your logic here and delete this line
	err := redisinit.CartDel(in.UsersId, in.GoodsId)
	if err != nil {
		logx.Error("购物车删除失败")
		return nil, errors.New("购物车删除失败")
	}
	return &goods.DelCartResponse{
		Success: true,
	}, nil
}
